package com.ruoyi.web.controller.installation;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WaterMeter;
import com.ruoyi.system.service.IWaterMeterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 表具信息Controller
 * 
 * @author ruoyi
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/installation/waterMeter")
public class WaterMeterController extends BaseController
{
    @Autowired
    private IWaterMeterService waterMeterService;

    /**
     * 查询表具信息列表
     */
    @PreAuthorize("@ss.hasPermi('installation:waterMeter:list')")
    @GetMapping("/list")
    public TableDataInfo list(WaterMeter waterMeter)
    {
        startPage();
        List<WaterMeter> list = waterMeterService.selectWaterMeterList(waterMeter);
        return getDataTable(list);
    }

    /**
     * 导出表具信息列表
     */
    @PreAuthorize("@ss.hasPermi('installation:waterMeter:export')")
    @Log(title = "表具信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WaterMeter waterMeter)
    {
        List<WaterMeter> list = waterMeterService.selectWaterMeterList(waterMeter);
        ExcelUtil<WaterMeter> util = new ExcelUtil<WaterMeter>(WaterMeter.class);
        util.exportExcel(response, list, "表具信息数据");
    }

    /**
     * 获取表具信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('installation:waterMeter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(waterMeterService.selectWaterMeterById(id));
    }

    /**
     * 新增表具信息
     */
    @PreAuthorize("@ss.hasPermi('installation:waterMeter:add')")
    @Log(title = "表具信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaterMeter waterMeter)
    {
        waterMeter.setCompanyId(getDeptId() + "");
        // waterMeter.setMeterNo(waterMeterService.getMaxMeterNo());
        return toAjax(waterMeterService.insertWaterMeter(waterMeter));
    }

    /**
     * 修改表具信息
     */
    @PreAuthorize("@ss.hasPermi('installation:waterMeter:edit')")
    @Log(title = "表具信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaterMeter waterMeter)
    {
        return toAjax(waterMeterService.updateWaterMeter(waterMeter));
    }

    /**
     * 删除表具信息
     */
    @PreAuthorize("@ss.hasPermi('installation:waterMeter:remove')")
    @Log(title = "表具信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(waterMeterService.deleteWaterMeterByIds(ids));
    }
}
